export function shuffle<T>(arr: T[]) {
	for (let i = 0; i < arr.length; i++) {
		const randomIndex = Math.round(Math.random() * (arr.length - 1 - i)) + i;
		[arr[i], arr[randomIndex]] = [arr[randomIndex], arr[i]];
	}
	return arr;
}

export function repeat<T>(arr: T[], times: number) {
	const arrCopy = arr.slice();
	for (let i = 0; i < times; i++) {
		arr = arr.concat(arrCopy);
	}
	return arr;
}
export function deepCopy<T>(target: T) {
	const copy = Object.create(Object.getPrototypeOf(target)) as T;
	const propNames = Object.getOwnPropertyNames(target);

	propNames.forEach(name => {
		const desc = Object.getOwnPropertyDescriptor(target, name);
		Object.defineProperty(copy, name, desc!);
	});

	return copy;
}
